package com.xianxing.article.controller;

import com.xianxing.article.service.ArticleService;
import com.xianxing.common.pojo.Article;
import com.xianxing.common.util.MessageConstant;
import com.xianxing.common.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.List;

@RestController
@RequestMapping("article")
@MapperScan(basePackages = {"com.xianxing.article.dao"})
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查询所有文章数据
     * @return
     */
    @GetMapping("/findAll")
    public Response<List<Article>> findAll() {
        List<Article> articleList = articleService.findAll();
        return Response.OK(MessageConstant.QUERY_ARTICLE_SUCCESS, articleList);
    }

    /**
     * 根据id查询文章
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Response findById(@PathVariable String id){
        Article article = articleService.findById(id);
        return Response.OK(MessageConstant.QUERY_ARTICLE_SUCCESS,article);
    }


}
